using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors.Repository;

namespace CsvCatcher.Setup
{
    public partial class OperationDlg : Form
    {
        
        public OperationDlg()
        {
            InitializeComponent();
            BindingList<Record> list = new BindingList<Record>();

            repositoryItemLookUpEdit.DataSource = Enum.GetValues(typeof(DataSchema.OperationType));
            repositoryItemLookUpEdit.ParseEditValue += new DevExpress.XtraEditors.Controls.ConvertEditValueEventHandler(repositoryItemComboBox_ParseEditValue);

            RepositoryItemImageComboBox item = new RepositoryItemImageComboBox();
            item.Items.AddRange(Enum.GetNames(typeof(DataSchema.OperationType)));
            gridControl1.RepositoryItems.Add(item);
            gridControl1.DataSource = list;
            gridView1.PopulateColumns();
            gridView1.Columns["EnumValue"].ColumnEdit = item;
            gridView1.Columns["EnumValue"].OptionsColumn.ReadOnly = false;
            gridView1.Columns["EnumValue"].OptionsColumn.AllowEdit = true;


            //repositoryItemLookUpEdit.DataBindings.Add("EditValue", list, "Status");

            //repositoryItemComboBox.Items.AddRange(Enum.GetNames(typeof(DataSchema.OperationType)));
            //repositoryItemComboBox.ParseEditValue += new DevExpress.XtraEditors.Controls.ConvertEditValueEventHandler(repositoryItemComboBox_ParseEditValue);

            //this.gridControl1.DataSource = list;
            
            /*gridView1.PopulateColumns();

            gridView1.Columns[0].ColumnEdit = repositoryItemComboBox;
            gridView1.Columns[0].OptionsColumn.ReadOnly = false;
            gridView1.Columns[0].OptionsColumn.AllowEdit = true;*/
        }

        void repositoryItemComboBox_ParseEditValue(object sender, DevExpress.XtraEditors.Controls.ConvertEditValueEventArgs e)
        {
            if (e.Value != null)
            {
                e.Value = (DataSchema.OperationType)Enum.Parse(typeof(DataSchema.OperationType), e.Value.ToString(), true);
                e.Handled = true;
            }
        }
    }

    class Record
    {
        public Record(DataSchema.OperationType eVal) { _enumValue = eVal; }
        DataSchema.OperationType _enumValue;
        public DataSchema.OperationType EnumValue { get { return _enumValue; } }
    }
}